﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.IO;
using System.Text;
using System.Collections;

using CE.User;
using CE.Global;
using CE.Report;
using CE.Database;
using CE.InputOut;
using CE.Mail;

public partial class car_mail_sending : System.Web.UI.Page
{
    string PageCode = "CXRPTCITREMLS";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Convert.ToInt64(Session[General.UserId].ToString()) != 1)
            {
                CheckPageAccess();
            }
            ClearFields();
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //if (Server.HtmlEncode(txtSearch.Text).Trim() != "")
        //{
        //    txtCarId.Text = CE.Global.General.GetCarId(Server.HtmlEncode(txtSearch.Text).Trim());
        //    LoadApplicationDetails(Convert.ToInt64(txtCarId.Text.Trim()), ddlPackageType.Text);
        //}
    }

    protected void btnGenerateExcel_Click(object sender, EventArgs e)
    {
    }

    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (ddlPackageType.Text == "ONLINE")
            {
                if (ddlWhoEmail.Text == "CUST")
                {
                    if (SendOnlineCustomerMail(ddlToWho.Text))
                    {
                        txtTesterEmail.Text = "";
                        lblMessage.Text = "Mail Successfully Sent";
                        lblError.Text = "";
                    }
                    else
                    {
                        lblMessage.Text = "";
                        lblError.Text = "Mail Sending Fail";
                    }
                }
                else if (ddlWhoEmail.Text == "PROV")
                {
                    if (SendOnlineProviderMail(ddlToWho.Text))
                    {
                        txtTesterEmail.Text = "";
                        lblMessage.Text = "Mail Successfully Sent";
                        lblError.Text = "";
                    }
                    else
                    {
                        lblMessage.Text = "";
                        lblError.Text = "Mail Sending Fail";
                    }
                }
            }
            else if (ddlPackageType.Text == "NONGG")
            {
                if (ddlWhoEmail.Text == "CUST")
                {
                    if (SendNonGGCustomerMail(ddlToWho.Text))
                    {
                        lblMessage.Text = "Mail Successfully Sent";
                        lblError.Text = "";
                    }
                    else
                    {
                        lblMessage.Text = "";
                        lblError.Text = "Mail Sending Fail";
                    }
                }
                else if (ddlWhoEmail.Text == "PROV")
                {
                    if (SendNonGGProviderMail(ddlToWho.Text))
                    {
                        lblMessage.Text = "Mail Successfully Sent";
                        lblError.Text = "";
                    }
                    else
                    {
                        lblMessage.Text = "";
                        lblError.Text = "Mail Sending Fail";
                    }
                }
            }
        }
    }

    public void LoadApplicationDetails(Int64 CarId, string PackageType)
    {
        lblSearchMessage.Text = "";
        DataSet _dsApplication = new DataSet();
        ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
        _dsApplication = _proposalsummarydb.GetGGCarApplicationDetails(CarId, PackageType);
        if (_dsApplication != null && _dsApplication.Tables.Count > 0 && _dsApplication.Tables[0].Rows.Count > 0)
        {
            pnlCarDetails.Visible = true;
            #region Assign Values
            txtExcel.Text = "";
            txtPDF1.Text = "";
            txtPDF2.Text = "";
            txtPDF3.Text = "";
            lblUpExcel.Text = "Not Found";
            lblUpPDF.Text = "Not Found";
            lblUpRefNo.Text = _dsApplication.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            lblUpApplicantName.Text = _dsApplication.Tables[0].Rows[0]["Name"].ToString();
            lblUpInsurer.Text = _dsApplication.Tables[0].Rows[0]["InsurerName"].ToString();
            lblUpPlanName.Text = _dsApplication.Tables[0].Rows[0]["CoverTypeDesc"].ToString();
            lblUpPremium.Text = _dsApplication.Tables[0].Rows[0]["TotalPremium"].ToString();
            txtProviderId.Text = _dsApplication.Tables[0].Rows[0]["ProviderCompanyId"].ToString();
            txtUserId.Text = _dsApplication.Tables[0].Rows[0]["RefCEUserId"].ToString();
            lblUpPaymentType.Text = _dsApplication.Tables[0].Rows[0]["PaymentType"].ToString();
            lblUpPaymentStatus.Text = _dsApplication.Tables[0].Rows[0]["PaymentStatus"].ToString();
            lblUpApplicationStatus.Text = _dsApplication.Tables[0].Rows[0]["CancelStatus"].ToString();
            if (_dsApplication.Tables[0].Rows[0]["Excel"].ToString() != "N/A")
            {
                lblUpExcel.Text = "Generated";
                txtExcel.Text = _dsApplication.Tables[0].Rows[0]["Excel"].ToString();
            }
            //else
            //{
            //    trGenerateExcel.Visible = true;
            //}
            if (_dsApplication.Tables.Count > 1 && _dsApplication.Tables[1].Rows.Count > 0)
            {
                lblUpPDF.Text = "Uploaded";
                if (_dsApplication.Tables[1].Rows.Count > 0)
                {
                    txtPDF1.Text = _dsApplication.Tables[1].Rows[0]["FileName"].ToString();
                }
                if (_dsApplication.Tables[1].Rows.Count > 1)
                {
                    txtPDF2.Text = _dsApplication.Tables[1].Rows[1]["FileName"].ToString();
                }
                if (_dsApplication.Tables[1].Rows.Count > 2)
                {
                    txtPDF3.Text = _dsApplication.Tables[1].Rows[2]["FileName"].ToString();
                }
            }
            if (lblUpExcel.Text == "Generated" && lblUpPDF.Text == "Uploaded")
            {
                pnlMail.Visible = true;
                pnlTester.Visible = true;
            }
            //if (lblUpExcel.Text != "Generated" && lblUpPDF.Text == "Uploaded")
            //{
            //    trGenerateExcel.Visible = true;
            //}
            #endregion
        }
        else
        {
            ClearFields();
            lblSearchMessage.Text = "Record not found. Please check your Package Type or QuoteRefNo";
        }
    }

    public string GetReferenceNumber(string Number, string ProviderId)
    {
        string convertno = CE.Global.General.GetRefNumber(Convert.ToInt64(Number.ToString()));
        string _RefNo = "";
        if (ProviderId == "11")
        {
            _RefNo = "AZC" + convertno.ToString();
        }
        else if (ProviderId == "12")
        {
            _RefNo = "MSI" + convertno.ToString();
        }
        else if (ProviderId == "16")
        {
            _RefNo = "AXA" + convertno.ToString();
        }
        else if (ProviderId == "29")
        {
            _RefNo = "LMG" + convertno.ToString();
        }
        else if (ProviderId == "31")
        {
            _RefNo = "CTS" + convertno.ToString();
        }
        else if (ProviderId == "32")
        {
            _RefNo = "BKI" + convertno.ToString();
        }
        else if (ProviderId == "33")
        {
            _RefNo = "MTI" + convertno.ToString();
        }
        else if (ProviderId == "41")
        {
            _RefNo = "KUR" + convertno.ToString();
        }
        else if (ProviderId == "46")
        {
            _RefNo = "TMS" + convertno.ToString();
        }
        return _RefNo;
    }

    private string GetProvider(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "azcp";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "msig";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "axa";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "lmg";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "cts";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "bki";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "mti";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "kur";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "tms";
        }
        return _result;
    }

    private string GetProviderName(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "อลิอันซ์ ซี.พี. ประกันภัย";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "เอ็ม เอส ไอ จี ประกันภัย";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "แอกซ่า ประกันภัย";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "แอลเอ็มจี ประกันภัย";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "กรุงเทพประกันภัย";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "เมืองไทยประกันภัย";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "คูเนีย ประกันภัย";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "โตเกียวมารีนศรีเมือง";
        }
        return _result;
    }

    private string GetProviderBrokerCode(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "001600";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "AFM1012";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "BH019";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "BR00619";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "002851000";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "641100";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "74000352";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "198700-00";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "10233002";
        }
        return _result;
    }

    private string GetProviderMail(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "TO_AZCP";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "TO_MSIG";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "TO_AXA";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "TO_LMG";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "TO_CTS";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "TO_BKI";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "TO_MTI";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "TO_KUR";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "TO_TMS";
        }
        return _result;
    }

    protected void ddlToWho_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlTester.Visible = false;
        rfvTesterEmail.Enabled = false;
        revTesterEmail.Enabled = false;
        if (ddlToWho.Text == "TEST")
        {
            pnlTester.Visible = true;
            rfvTesterEmail.Enabled = true;
            revTesterEmail.Enabled = true;
        }
    }

    protected void ddlPackageType_SelectedIndexChanged(object sender, EventArgs e)
    {
        ClearFields();
    }

    public void ClearFields()
    {
        trGenerateExcel.Visible = false;
        txtCarId.Text = "";
        txtProviderId.Text = "";
        txtUserId.Text = "";
        txtTesterEmail.Text = "";
        pnlMail.Visible = false;
        pnlTester.Visible = false;
        pnlCarDetails.Visible = false;
        rfvTesterEmail.Enabled = false;
        revTesterEmail.Enabled = false;
        if (ddlToWho.Text == "TEST")
        {
            pnlTester.Visible = true;
            rfvTesterEmail.Enabled = true;
            revTesterEmail.Enabled = true;
        }
    }

    public bool SendOnlineCustomerMail(string TOWHO)
    {
        bool _mailstatus = false;
        string _toemail = "";
        string _ccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CC");
        string _bccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BCC");
        if (TOWHO == "TEST")
        {
            _toemail = txtTesterEmail.Text;
        }
        else
        {
            Int64 _Provider = Convert.ToInt64(txtProviderId.Text);
            string TO = GetProviderMail(_Provider);
            _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue(TO);
        }
        if (_toemail.Length > 0)
        {
            string _CustName, _Today, _QuoteRefNo, _CustAddress, _Payment, _OrderRefNo, _CoverTypeDesc, _AnnualPremium, _MakeModelDesc, _CustEmail;
            _CustName = ""; _Today = ""; _QuoteRefNo = ""; _CustAddress = ""; _Payment = ""; _OrderRefNo = ""; _CoverTypeDesc = "";
            _AnnualPremium = ""; _MakeModelDesc = ""; _CustEmail = "";

            Int64 CarId = Convert.ToInt64(txtCarId.Text);
            Int64 ProviderCompanyId = Convert.ToInt64(txtProviderId.Text);
            DataSet _dsUserData = new DataSet();
            ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
            _dsUserData = _proposalsummarydb.GetCompletedUserItem(CarId, ProviderCompanyId);
            if (_dsUserData != null && _dsUserData.Tables.Count > 0 && _dsUserData.Tables[0].Rows.Count > 0)
            {
                _CustName = _dsUserData.Tables[0].Rows[0]["Name"].ToString();
                _Today = _dsUserData.Tables[0].Rows[0]["Today"].ToString();
                _QuoteRefNo = _dsUserData.Tables[0].Rows[0]["QuoteRefNo"].ToString();
                _CustAddress = _dsUserData.Tables[0].Rows[0]["CustAddress"].ToString();
                if (_dsUserData.Tables[0].Rows[0]["Payment"].ToString() == "BT")
                {
                    if (ddlLanguage.Text == "TH")
                    {
                        _Payment = "ผ่านบัญชีธนาคาร";
                    }
                    else if (ddlLanguage.Text == "EN")
                    {
                        _Payment = "Bank Transfer";
                    }
                }
                else if (_dsUserData.Tables[0].Rows[0]["Payment"].ToString() == "CC")
                {
                    if (ddlLanguage.Text == "TH")
                    {
                        _Payment = "บัตรเครดิต";
                    }
                    else if (ddlLanguage.Text == "EN")
                    {
                        _Payment = "Credit Card";
                    }
                }

                _OrderRefNo = _dsUserData.Tables[0].Rows[0]["OrderRefNo"].ToString();
                _CoverTypeDesc = _dsUserData.Tables[0].Rows[0]["CoverTypeDesc"].ToString();
                _AnnualPremium = _dsUserData.Tables[0].Rows[0]["AnnualPremium"].ToString();
                _MakeModelDesc = _dsUserData.Tables[0].Rows[0]["MakeModelDesc"].ToString();
                _CustEmail = _dsUserData.Tables[0].Rows[0]["Email"].ToString();
                if (TOWHO != "TEST")
                {
                    _toemail = _CustEmail;
                }
                else
                {
                    _ccemail = "";
                    _bccemail = "";
                }
            }

            string imgUrl = "http://" + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");
            string mailBody = "";
            string _emailTitle = "";

            mailBody += "<html>";
            mailBody += "<head>";
            mailBody += "<title></title>";
            mailBody += "<style type='text/css'>";
            mailBody += "body{ font-family:Arial, Helvetica, sans-serif; font-size:14px;}";
            mailBody += "p{line-height: 1.5em; padding:0; margin:0;}";
            mailBody += ".line{border-bottom: 1px #000 solid; padding-bottom: 1px;}";
            mailBody += ".tblbrd{ border: 2px solid #000;}";
            mailBody += "</style>";
            mailBody += "</head>";
            mailBody += "<body>";

            if (ddlLanguage.Text == "TH")
            {
                _emailTitle = "การยืนยันประกันภัยรถยนต์ สำหรับ กล้วยๆ.com [" + _QuoteRefNo + "]";

                mailBody += "<table width='670' border='0' cellpadding='2' cellspacing='2' class='tblbrd'>";
                mailBody += "<tr><td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='140' height='100' rowspan='4'><img src='" + imgUrl + "' alt='GluayGluay' width='120' height='100' /></td>";
                mailBody += "<td><b>บริษัทคอมแพร์เอ็กซ์เพรส นายหน้าประกันวินาศภัย (ประเทศไทย) จำกัด</b></td>";
                mailBody += "</tr>";
                mailBody += "<tr><td>2 อาคาร เค.ซี.ซี. ชั้น 2 สีลมซอย 9 ถนนสีลม เขตบางรัก กรุงเทพฯ 10500</td></tr>";
                mailBody += "<tr><td>โทร 02-268-8222 โทรสาร 02-266-6321</td></tr>";
                mailBody += "<tr><td>อีเมล์: support@gluaygluay.com</td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr><td height='25' align='center'><b>เอกสารยืนยันการได้รับค่าเบี้ยประกันภัย</b></td></tr>";
                mailBody += "<tr><td align='right'><table width='100%' border='0' cellpadding='0' cellspacing='2'>";
                mailBody += "<tr>";
                mailBody += "<td align='right'>&nbsp;</td>";
                mailBody += "<td width='100' align='right'>วันที่ : &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _Today + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td align='left'>ได้รับค่าเบี้ยประกันภัย จาก</td>";
                mailBody += "<td width='100' align='right'>เลขที่อ้างอิง: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _QuoteRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>คุณ:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustName + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ที่อยู่ :</td>";
                mailBody += "<td valign='top' class='line'>" + _CustAddress + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ประเภทกรมธรรม์:</td>";
                mailBody += "<td valign='top' class='line'>" + _CoverTypeDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ยี่ห้อรถยนต์/รุ่นรถยนต์:</td>";
                mailBody += "<td valign='top' class='line'>" + _MakeModelDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td colspan='2' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150'>เบี้ยประกันภัยรายปี เป็นเงิน </td>";
                mailBody += "<td width='150' class='line'>" + _AnnualPremium + "</td>";
                mailBody += "<td width='150' colspan='2'>&nbsp;&nbsp;บาท &nbsp; (รวมอากรแสตมป์และภาษีมูลค่าเพิ่ม)</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='4'></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td>ชำระโดย</td>";
                mailBody += "<td class='line'>" + _Payment + "</td>";
                mailBody += "<td width='150' align='right'>หมายเลขอ้างอิง &nbsp;&nbsp;</td>";
                mailBody += "<td class='line'>" + _OrderRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><span class='line'><br />หมายเหตุ</span>";
                mailBody += "<p>เอกสารฉบับนี้จัดทำด้วยระบบคอมพิวเตอร์ ถือว่าสมบูรณ์โดยไม่ต้องมีลายมือชื่อผู้รับมอบอำนาจ<br /></p></td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td>ใบเสร็จรับเงินตัวจริงจะทำการออกให้ท่านโดยบริษัทประกันฯ และส่งให้ท่านพร้อมกับกรมธรรม์ต่อไป</td>";
                mailBody += "</tr></table><br />";
                mailBody += "</body>";
                mailBody += "</html>";
            }
            else if (ddlLanguage.Text == "EN")
            {
                _emailTitle = "Car Insurance Submission on GluayGluay.com [" + _QuoteRefNo + "]";

                mailBody += "<table width='670' border='0' cellpadding='2' cellspacing='2' class='tblbrd'>";
                mailBody += "<tr><td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='140' height='100' rowspan='4'><img src='" + imgUrl + "' alt='GluayGluay' width='120' height='100' /></td>";
                mailBody += "<td><b>CompareXpress Non-Life Insurance Broker (Thailand) Ltd.</b></td>";
                mailBody += "</tr>";
                mailBody += "<tr><td>2 K.C.C. Building 2nd floor  Silom Soi 9 Silom Road Bangrak Bangkok 10500</td></tr>";
                mailBody += "<tr><td>t : +66 2 268 8222  f : +66 2 266 6321</td></tr>";
                mailBody += "<tr><td>e: support@gluaygluay.com</td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr><td height='25' align='center'><b>Confirmation of Insurance Premium Payment</b></td></tr>";
                mailBody += "<tr><td align='right'><table width='100%' border='0' cellpadding='0' cellspacing='2'>";
                mailBody += "<tr>";
                mailBody += "<td align='right'>&nbsp;</td>";
                mailBody += "<td width='100' align='right'>Date: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _Today + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td align='left'>Premium received from</td>";
                mailBody += "<td width='100' align='right'>Ref No: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _QuoteRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Name:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustName + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Address:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustAddress + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Type of policy:</td>";
                mailBody += "<td valign='top' class='line'>" + _CoverTypeDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Make/Model:</td>";
                mailBody += "<td valign='top' class='line'>" + _MakeModelDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td colspan='2' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150'>Annual Premium</td>";
                mailBody += "<td width='150' class='line'>" + _AnnualPremium + "</td>";
                mailBody += "<td width='150' colspan='2'>&nbsp;&nbsp;Baht &nbsp; (Duty Stamp &amp; VAT Included)</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='4'></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td>Paid by</td>";
                mailBody += "<td class='line'>" + _Payment + "</td>";
                mailBody += "<td width='150' align='right'>Reference no. &nbsp;&nbsp;</td>";
                mailBody += "<td class='line'>" + _OrderRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><span class='line'><br />Remarks</span>";
                mailBody += "<p>This is computer generated confirmation, no signature is required<br /></p></td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td>The official receipt of premium payment will be issued by the insurance company upon policy approval and will be sent together with policy documents</td>";
                mailBody += "</tr></table><br />";
                mailBody += "</body>";
                mailBody += "</html>";
            }

            _mailstatus = MyMailManager.SendToCustomer(_toemail, _ccemail, _bccemail, _emailTitle, mailBody);
        }
        return _mailstatus;
    }

    public bool SendNonGGCustomerMail(string TOWHO)
    {
        bool _mailstatus = false;
        string _toemail = "";
        string _ccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CC");
        string _bccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BCC");
        if (TOWHO == "TEST")
        {
            _toemail = txtTesterEmail.Text;
        }
        else
        {
            Int64 _Provider = Convert.ToInt64(txtProviderId.Text);
            string TO = GetProviderMail(_Provider);
            _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue(TO);
        }
        if (_toemail.Length > 0)
        {
            string _CustName, _Today, _QuoteRefNo, _CustAddress, _Payment, _OrderRefNo, _CoverTypeDesc, _AnnualPremium, _MakeModelDesc, _CustEmail, _Language;
            _CustName = ""; _Today = ""; _QuoteRefNo = ""; _CustAddress = ""; _Payment = ""; _OrderRefNo = ""; _CoverTypeDesc = ""; _Language = "TH";
            _AnnualPremium = ""; _MakeModelDesc = ""; _CustEmail = "";
            if (ddlLanguage.Text == "EN")
                _Language = "EN";
            Int64 CECarId = Convert.ToInt64(txtCarId.Text.Trim());
            Int64 RefCEUserId = Convert.ToInt64(txtUserId.Text.Trim());
            Int64 ProviderCompanyId = Convert.ToInt64(txtProviderId.Text.Trim());
            DataSet _dsUserData = new DataSet();
            ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
            _dsUserData = _proposalsummarydb.GetNonGGCompletedUserItem(CECarId, RefCEUserId, ProviderCompanyId);
            if (_dsUserData != null && _dsUserData.Tables.Count > 1 && _dsUserData.Tables[1].Rows.Count > 0)
            {
                _CustName = _dsUserData.Tables[1].Rows[0]["Name"].ToString();
                _Today = _dsUserData.Tables[1].Rows[0]["Today"].ToString();
                _QuoteRefNo = _dsUserData.Tables[1].Rows[0]["QuoteRefNo"].ToString();
                _CustAddress = _dsUserData.Tables[1].Rows[0]["CustAddress"].ToString();
                if (_dsUserData.Tables[1].Rows[0]["PaymentType"].ToString() == "BT")
                {
                    if (_Language.ToString() == "TH")
                    {
                        _Payment = "ผ่านบัญชีธนาคาร";
                    }
                    else if (_Language.ToString() == "EN")
                    {
                        _Payment = "Bank Transfer";
                    }
                }
                else if (_dsUserData.Tables[1].Rows[0]["PaymentType"].ToString() == "CC")
                {
                    if (_Language.ToString() == "TH")
                    {
                        _Payment = "บัตรเครดิต";
                    }
                    else if (_Language.ToString() == "EN")
                    {
                        _Payment = "Credit Card";
                    }
                }

                _OrderRefNo = _dsUserData.Tables[1].Rows[0]["ReceiptNo"].ToString();
                _CoverTypeDesc = _dsUserData.Tables[1].Rows[0]["Package"].ToString();
                _AnnualPremium = _dsUserData.Tables[1].Rows[0]["TotalPremium"].ToString();
                _MakeModelDesc = _dsUserData.Tables[1].Rows[0]["CarModel"].ToString();
                _CustEmail = _dsUserData.Tables[1].Rows[0]["Email"].ToString();
                if (TOWHO != "TEST")
                {
                    _toemail = _CustEmail;
                }
                else
                {
                    _ccemail = "";
                    _bccemail = "";
                }
            }

            string imgUrl = "http://" + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");
            string mailBody = "";
            string _emailTitle = "";

            mailBody += "<html>";
            mailBody += "<head>";
            mailBody += "<title></title>";
            mailBody += "<style type='text/css'>";
            mailBody += "body{ font-family:Arial, Helvetica, sans-serif; font-size:14px;}";
            mailBody += "p{line-height: 1.5em; padding:0; margin:0;}";
            mailBody += ".line{border-bottom: 1px #000 solid; padding-bottom: 1px;}";
            mailBody += ".tblbrd{ border: 2px solid #000;}";
            mailBody += "</style>";
            mailBody += "</head>";
            mailBody += "<body>";

            if (_Language.ToString() == "TH")
            {
                _emailTitle = "การยืนยันประกันภัยรถยนต์ สำหรับ กล้วยๆ.com [" + _QuoteRefNo + "]";

                mailBody += "<table width='670' border='0' cellpadding='2' cellspacing='2' class='tblbrd'>";
                mailBody += "<tr><td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='140' height='100' rowspan='4'><img src='" + imgUrl + "' alt='GluayGluay' width='120' height='100' /></td>";
                mailBody += "<td><b>บริษัทคอมแพร์เอ็กซ์เพรส นายหน้าประกันวินาศภัย (ประเทศไทย) จำกัด</b></td>";
                mailBody += "</tr>";
                mailBody += "<tr><td>2 อาคาร เค.ซี.ซี. ชั้น 2 สีลมซอย 9 ถนนสีลม เขตบางรัก กรุงเทพฯ 10500</td></tr>";
                mailBody += "<tr><td>โทร 02-268-8222 โทรสาร 02-266-6321</td></tr>";
                mailBody += "<tr><td>อีเมล์: support@gluaygluay.com</td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr><td height='25' align='center'><b>เอกสารยืนยันการได้รับค่าเบี้ยประกันภัย</b></td></tr>";
                mailBody += "<tr><td align='right'><table width='100%' border='0' cellpadding='0' cellspacing='2'>";
                mailBody += "<tr>";
                mailBody += "<td align='right'>&nbsp;</td>";
                mailBody += "<td width='100' align='right'>วันที่ : &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _Today + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td align='left'>ได้รับค่าเบี้ยประกันภัย จาก</td>";
                mailBody += "<td width='100' align='right'>เลขที่อ้างอิง: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _QuoteRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>คุณ:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustName + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ที่อยู่ :</td>";
                mailBody += "<td valign='top' class='line'>" + _CustAddress + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ประเภทกรมธรรม์:</td>";
                mailBody += "<td valign='top' class='line'>" + _CoverTypeDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>ยี่ห้อรถยนต์/รุ่นรถยนต์:</td>";
                mailBody += "<td valign='top' class='line'>" + _MakeModelDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td colspan='2' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150'>เบี้ยประกันภัยรายปี เป็นเงิน </td>";
                mailBody += "<td width='150' class='line'>" + _AnnualPremium + "</td>";
                mailBody += "<td width='150' colspan='2'>&nbsp;&nbsp;บาท &nbsp; (รวมอากรแสตมป์และภาษีมูลค่าเพิ่ม)</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='4'></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td>ชำระโดย</td>";
                mailBody += "<td class='line'>" + _Payment + "</td>";
                mailBody += "<td width='150' align='right'>หมายเลขอ้างอิง &nbsp;&nbsp;</td>";
                mailBody += "<td class='line'>" + _OrderRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><span class='line'><br />หมายเหตุ</span>";
                mailBody += "<p>เอกสารฉบับนี้จัดทำด้วยระบบคอมพิวเตอร์ ถือว่าสมบูรณ์โดยไม่ต้องมีลายมือชื่อผู้รับมอบอำนาจ<br /></p></td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td>ใบเสร็จรับเงินตัวจริงจะทำการออกให้ท่านโดยบริษัทประกันฯ และส่งให้ท่านพร้อมกับกรมธรรม์ต่อไป</td>";
                mailBody += "</tr></table><br />";
                mailBody += "</body>";
                mailBody += "</html>";
            }
            else if (_Language.ToString() == "EN")
            {
                _emailTitle = "Car Insurance Submission on GluayGluay.com [" + _QuoteRefNo + "]";

                mailBody += "<table width='670' border='0' cellpadding='2' cellspacing='2' class='tblbrd'>";
                mailBody += "<tr><td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='140' height='100' rowspan='4'><img src='" + imgUrl + "' alt='GluayGluay' width='120' height='100' /></td>";
                mailBody += "<td><b>CompareXpress Non-Life Insurance Broker (Thailand) Ltd.</b></td>";
                mailBody += "</tr>";
                mailBody += "<tr><td>2 K.C.C. Building 2nd floor  Silom Soi 9 Silom Road Bangrak Bangkok 10500</td></tr>";
                mailBody += "<tr><td>t : +66 2 268 8222  f : +66 2 266 6321</td></tr>";
                mailBody += "<tr><td>e: support@gluaygluay.com</td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr><td height='25' align='center'><b>Confirmation of Insurance Premium Payment</b></td></tr>";
                mailBody += "<tr><td align='right'><table width='100%' border='0' cellpadding='0' cellspacing='2'>";
                mailBody += "<tr>";
                mailBody += "<td align='right'>&nbsp;</td>";
                mailBody += "<td width='100' align='right'>Date: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _Today + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td align='left'>Premium received from</td>";
                mailBody += "<td width='100' align='right'>Ref No: &nbsp;</td>";
                mailBody += "<td width='100' align='left' class='line'>" + _QuoteRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><table width='100%' border='0' cellspacing='2' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Name:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustName + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Address:</td>";
                mailBody += "<td valign='top' class='line'>" + _CustAddress + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Type of policy:</td>";
                mailBody += "<td valign='top' class='line'>" + _CoverTypeDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td width='150' valign='top'>Make/Model:</td>";
                mailBody += "<td valign='top' class='line'>" + _MakeModelDesc + "</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='2' valign='top'>&nbsp;</td></tr>";
                mailBody += "<tr>";
                mailBody += "<td colspan='2' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                mailBody += "<tr>";
                mailBody += "<td width='150'>Annual Premium</td>";
                mailBody += "<td width='150' class='line'>" + _AnnualPremium + "</td>";
                mailBody += "<td width='150' colspan='2'>&nbsp;&nbsp;Baht &nbsp; (Duty Stamp &amp; VAT Included)</td>";
                mailBody += "</tr>";
                mailBody += "<tr><td height='10' colspan='4'></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td>Paid by</td>";
                mailBody += "<td class='line'>" + _Payment + "</td>";
                mailBody += "<td width='150' align='right'>Reference no. &nbsp;&nbsp;</td>";
                mailBody += "<td class='line'>" + _OrderRefNo + "</td>";
                mailBody += "</tr>";
                mailBody += "</table></td></tr>";
                mailBody += "</table></td></tr>";
                mailBody += "<tr>";
                mailBody += "<td><span class='line'><br />Remarks</span>";
                mailBody += "<p>This is computer generated confirmation, no signature is required<br /></p></td>";
                mailBody += "</tr>";
                mailBody += "<tr>";
                mailBody += "<td>The official receipt of premium payment will be issued by the insurance company upon policy approval and will be sent together with policy documents</td>";
                mailBody += "</tr></table><br />";
                mailBody += "</body>";
                mailBody += "</html>";
            }

            _mailstatus = MyMailManager.SendToCustomer(_toemail, _ccemail, _bccemail, _emailTitle, mailBody);
        }
        return _mailstatus;
    }

    public bool SendOnlineProviderMail(string TOWHO)
    {
        bool _mailstatus = false;
        int Count = 0;
        string[] _fileList = new string[0];
        string _ProToEmail = "";
        string _ProCCEmail = "";
        string _ProBCCEmail = "";

        if (TOWHO == "TEST")
        {
            _ProToEmail = txtTesterEmail.Text;
        }
        else
        {
            Int64 _Provider = Convert.ToInt64(txtProviderId.Text);
            string TO = GetProviderMail(_Provider);
            _ProToEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue(TO);
            _ProCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CC");
            _ProBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BCC");
        }
        if (txtExcel.Text.Trim().Length > 20 && (txtPDF1.Text.Trim().Length > 20 || txtPDF2.Text.Trim().Length > 20 || txtPDF3.Text.Trim().Length > 20))
        {
            Count += 1;
            if (txtPDF1.Text.Trim().Length > 20)
            {
                Count += 1;
            }
            if (txtPDF2.Text.Trim().Length > 20)
            {
                Count += 1;
            }
            if (txtPDF3.Text.Trim().Length > 20)
            {
                Count += 1;
            }
        }
        if (_ProToEmail.Length > 0 && Count > 1)
        {
            if (txtExcel.Text.Trim().Length > 20 && Count > 1)
            {
                _fileList = new string[Count];
                for (int b = 0; b < _fileList.Length; b++)
                {
                    if (b == 0)
                    {
                        _fileList[b] = txtExcel.Text.Trim();
                    }
                    if (txtPDF1.Text.Trim().Length > 20 && b == 1)
                    {
                        _fileList[b] = txtPDF1.Text.Trim();
                    }
                    if (txtPDF2.Text.Trim().Length > 20 && b == 2)
                    {
                        _fileList[b] = txtPDF2.Text.Trim();
                    }
                    if (txtPDF3.Text.Trim().Length > 20 && b == 3)
                    {
                        _fileList[b] = txtPDF3.Text.Trim();
                    }
                }
            }

            string _ProMailBody, _ProEmailTitle, _ProviderName, ProviderBrokerCode, _QuoteRefNo;
            _ProMailBody = ""; _ProEmailTitle = ""; _ProCCEmail = ""; _ProBCCEmail = ""; _QuoteRefNo = "";
            _ProviderName = GetProviderName(Convert.ToInt64(txtProviderId.Text.Trim()));
            ProviderBrokerCode = GetProviderBrokerCode(Convert.ToInt64(txtProviderId.Text.Trim()));

            Int64 CarId = Convert.ToInt64(txtCarId.Text);
            Int64 ProviderCompanyId = Convert.ToInt64(txtProviderId.Text);
            DataSet _dsUserData = new DataSet();
            ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
            _dsUserData = _proposalsummarydb.GetCompletedUserItem(CarId, ProviderCompanyId);
            if (_dsUserData != null && _dsUserData.Tables.Count > 0 && _dsUserData.Tables[0].Rows.Count > 0)
            {
                _QuoteRefNo = _dsUserData.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            }
            _ProEmailTitle = "ส่งงานประกันรถยนต์ – motor insurance application from CompareXpress [" + _QuoteRefNo + "]";
            _ProMailBody += "<br>เรียน ฝ่ายพิจารณารับประกัน บริษัท  " + _ProviderName + ",<br><br>";
            _ProMailBody += "บริษัท คอมแพร์เอ็กซ์เพรส นายหน้าประกันวินาศภัย (ประเทศไทย) จำกัด, เลขที่นายหน้า [" + ProviderBrokerCode + "]  มีความประสงค์ขอส่งงานประกันภัยรถยนต์ตามรายละเอียดในไฟล์แนบ<br><br>";
            _ProMailBody += "กรุณาติดต่อ 0-2268-8222 ต่อ 2229 หากข้อมูลไม่ครบถ้วน หรือหากต้องการสอบถามรายละเอียดเพิ่มเติม ขอบคุณค่ะ<br><br>";
            _ProMailBody += "ขอแสดงความนับถือ<br/><br>";
            _ProMailBody += "<hr align='left' width='410px' /><br>";
            _ProMailBody += "<b>CompareXpress Non-Life Insurance Broker (Thailand) Ltd.</b><br>";
            _ProMailBody += "2 K.C.C. Building 2nd floor<br />";
            _ProMailBody += "Silom Soi 9 Silom Road Bangrak <br />";
            _ProMailBody += "Bangkok 10500<br />";
            _ProMailBody += "t : +66 2 268 8222<br />";
            _ProMailBody += "f : +66 2 266 6321 <br />";

            _mailstatus = MyMailManager.SendToProviderWithAttach(_ProToEmail, _ProCCEmail, _ProBCCEmail, _ProEmailTitle, _ProMailBody, _fileList);
        }
        return _mailstatus;
    }

    public bool SendNonGGProviderMail(string TOWHO)
    {
        bool _mailstatus = false;
        int Count = 0;
        string[] _fileList = new string[0];
        string _ProToEmail = "";
        string _ProCCEmail = "";
        string _ProBCCEmail = "";

        if (TOWHO == "TEST")
        {
            _ProToEmail = txtTesterEmail.Text;
        }
        else
        {
            Int64 _Provider = Convert.ToInt64(txtProviderId.Text);
            string TO = GetProviderMail(_Provider);
            _ProToEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue(TO);
            _ProCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CC");
            _ProBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("BCC");
        }
        if (txtExcel.Text.Trim().Length > 20 && (txtPDF1.Text.Trim().Length > 20 || txtPDF2.Text.Trim().Length > 20 || txtPDF3.Text.Trim().Length > 20))
        {
            Count += 1;
            if (txtPDF1.Text.Trim().Length > 20)
            {
                Count += 1;
            }
            if (txtPDF2.Text.Trim().Length > 20)
            {
                Count += 1;
            }
            if (txtPDF3.Text.Trim().Length > 20)
            {
                Count += 1;
            }
        }
        if (_ProToEmail.Length > 0 && Count > 1)
        {
            if (txtExcel.Text.Trim().Length > 20 && Count > 1)
            {
                _fileList = new string[Count];
                for (int b = 0; b < _fileList.Length; b++)
                {
                    _fileList[b] = txtExcel.Text.Trim();
                    if (txtPDF1.Text.Trim().Length > 20 && b == 1)
                    {
                        _fileList[b] = txtPDF1.Text.Trim();
                    }
                    if (txtPDF2.Text.Trim().Length > 20 && b == 2)
                    {
                        _fileList[b] = txtPDF2.Text.Trim();
                    }
                    if (txtPDF3.Text.Trim().Length > 20 && b == 3)
                    {
                        _fileList[b] = txtPDF3.Text.Trim();
                    }
                }
            }

            string _ProMailBody, _ProEmailTitle, _ProviderName, ProviderBrokerCode, _QuoteRefNo;
            _ProMailBody = ""; _ProEmailTitle = ""; _ProCCEmail = ""; _ProBCCEmail = ""; _QuoteRefNo = "";
            _ProviderName = GetProviderName(Convert.ToInt64(txtProviderId.Text.Trim()));
            ProviderBrokerCode = GetProviderBrokerCode(Convert.ToInt64(txtProviderId.Text.Trim()));

            Int64 CECarId = Convert.ToInt64(txtCarId.Text.Trim());
            Int64 RefCEUserId = Convert.ToInt64(txtUserId.Text.Trim());
            Int64 ProviderCompanyId = Convert.ToInt64(txtProviderId.Text.Trim());
            DataSet _dsUserData = new DataSet();
            ProposalSummaryDB _proposalsummarydb = new ProposalSummaryDB();
            _dsUserData = _proposalsummarydb.GetNonGGCompletedUserItem(CECarId, RefCEUserId, ProviderCompanyId);
            if (_dsUserData != null && _dsUserData.Tables.Count > 0 && _dsUserData.Tables[0].Rows.Count > 0)
            {
                _QuoteRefNo = _dsUserData.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            }
            _ProEmailTitle = "ส่งงานประกันรถยนต์ – motor insurance application from CompareXpress [" + _QuoteRefNo + "]";
            _ProMailBody += "<br>เรียน ฝ่ายพิจารณารับประกัน บริษัท  " + _ProviderName + ",<br><br>";
            _ProMailBody += "บริษัท คอมแพร์เอ็กซ์เพรส นายหน้าประกันวินาศภัย (ประเทศไทย) จำกัด, เลขที่นายหน้า [" + ProviderBrokerCode + "]  มีความประสงค์ขอส่งงานประกันภัยรถยนต์ตามรายละเอียดในไฟล์แนบ<br><br>";
            _ProMailBody += "กรุณาติดต่อ 0-2268-8222 ต่อ 2229 หากข้อมูลไม่ครบถ้วน หรือหากต้องการสอบถามรายละเอียดเพิ่มเติม ขอบคุณค่ะ<br><br>";
            _ProMailBody += "ขอแสดงความนับถือ<br/><br>";
            _ProMailBody += "<hr align='left' width='410px' /><br>";
            _ProMailBody += "<b>CompareXpress Non-Life Insurance Broker (Thailand) Ltd.</b><br>";
            _ProMailBody += "2 K.C.C. Building 2nd floor<br />";
            _ProMailBody += "Silom Soi 9 Silom Road Bangrak <br />";
            _ProMailBody += "Bangkok 10500<br />";
            _ProMailBody += "t : +66 2 268 8222<br />";
            _ProMailBody += "f : +66 2 266 6321 <br />";

            _mailstatus = MyMailManager.SendToProviderWithAttach(_ProToEmail, _ProCCEmail, _ProBCCEmail, _ProEmailTitle, _ProMailBody, _fileList);
        }
        return _mailstatus;
    }

    private void CheckPageAccess()
    {
        Int64 PageAccess = General.GetPageAccess(Convert.ToInt64(Session[General.UserId].ToString()), PageCode);
        if (PageAccess == 0)
        {
            Response.Redirect("~/UserMessage.aspx?menu=0&mt=UM&ec=101");
        }
        else
        {
            EnablePageAccess(PageAccess);
        }
    }

    private void EnablePageAccess(Int64 PageAccess)
    {
        if (PageAccess == 100)
        {
            btnSendMail.Enabled = false;
        }
        else if (PageAccess == 200)
        {
            btnSendMail.Enabled = true;
        }
    }

}
